//
// Created by ZCSD on 2021/10/13.
//

#include "SystemManager.h"
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

const char * SystemManager::getSizeOfType() {
    stringstream str;
    void* p =  0;
    int bit = sizeof(p);
    if (4 == bit) {
        str<<"当前是 32位系统\n";
    } else {
        str<<"当前是 64位系统\n";
    }

    str<<"指针的长度是:"<<sizeof(p)<<endl;
    str<<"short类型的长度是:"<<sizeof(short)<<endl;
    str<<"int类型的长度是:"<<sizeof(int)<<endl;
    str<<"long类型的长度是:"<<sizeof(long)<<endl;
    str<<"long long类型的长度是:"<<sizeof(long long)<<endl;
    str<<"float类型的长度是:"<<sizeof(float)<<endl;
    str<<"double类型的长度是:"<<sizeof(double)<<endl;
    str<<"bool类型的长度是:"<<sizeof(bool)<<endl;
    str<<"char类型的长度是:"<<sizeof(char)<<endl;
    str<<"intptr_t类型的长度是:"<<sizeof(intptr_t)<<endl;
    str<<"int8_t类型的长度是:"<<sizeof(int8_t)<<endl;
    str<<"int16_t类型的长度是:"<<sizeof(int16_t)<<endl;
    str<<"int32_t类型的长度是:"<<sizeof(int32_t)<<endl;
    str<<"int64_t类型的长度是:"<<sizeof(int64_t)<<endl;

    return str.str().c_str();
}

const char *SystemManager::freeTest() {
    stringstream str;
    str<<"空指针的地址为"<< static_cast<const void *>(nullptr)<<endl;
    char * arr = (char *)malloc(10*sizeof(char ));
    str<<"char * 指针释放之前的地址为"<<static_cast<const void *>(arr)<<endl;
    str<<"char * 指针释放之前的大小为"<<sizeof(arr)<<endl;
    free(arr);
    str<<"char * 指针释放之后的地址为"<<static_cast<const void *>(arr) <<endl;
    return str.str().c_str();
}
